<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="/template_bill.xhtml"
                    >
        <ui:define name="title">
            <h:outputText value="الفاتورة "></h:outputText>

        </ui:define>
        <ui:define name="body">
            <h:panelGroup id="messagePanel" layout="block">
                <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
            </h:panelGroup>
            <h:form> 
                <div class="form-inline well">
                    <label style="padding-left: 10px;" for="input04">رقم الفاتوره</label>
                    <h:inputText size="5" value="#{billInformationController.billNumber}" id="input04" readonly="true" /> 
                    <label style="padding-right: 20px; padding-left: 32px;" for="input04">رقم الدفتر </label>
                    <h:inputText size="5" value="#{billInformationController.docNumber}" readonly="true"/> 
                    <label style="padding-right: 20px; padding-left: 32px;" for="input05">التاريخ:</label>
                    <h:outputText value="#{billInformationController.CDate}"/>
                    <div class="clear"></div>
                    <center>
                        <label style="padding-left: 15px;" for="input06">اسم العميل</label>
                        <h:inputText  value="#{billInformationController.customerName}" readonly="true"/> 
                    </center>
                </div>



                <!-- start of the add form -->


                <h:dataTable value="#{billInformationController.add_Item}" var="added_item"

                             class="table table-condensed table-striped">

                    <h:column>
                        <f:facet name="header"> المنتج  </f:facet>
                        #{added_item.item}

                    </h:column>

                    <h:column>
                        <f:facet name="header"> المصنع  </f:facet>
                        #{added_item.factory}
                    </h:column>
                    <h:column>
                        <f:facet name="header"> البلد  </f:facet>
                        #{added_item.country}
                    </h:column>
                    <h:column>
                        <f:facet name="header"> العدد  </f:facet>

                        <h:inputText value="#{added_item.item_count}" size="5" rendered="#{added_item.editable}" />
                        <h:outputText value="#{added_item.item_count}" rendered="#{not added_item.editable}" />


                    </h:column>
                    <h:column>
                        <f:facet name="header"> الوزن   </f:facet>
                        <h:inputText value="#{added_item.item_quantity}" size="5" rendered="#{added_item.editable}" />
                        <h:outputText value="#{added_item.item_quantity}" rendered="#{not added_item.editable}" />


                    </h:column>
                    <h:column>
                        <f:facet name="header"> سعر الوحدة  </f:facet>
                        <h:inputText value="#{added_item.unit_price}" size="5" rendered="#{added_item.editable}" />
                        <h:outputText value="#{added_item.unit_price}" rendered="#{not added_item.editable}" />

                    </h:column>

                    <h:column>
                        <f:facet name="header"> الاجمالي  </f:facet>
                        <h:outputText value=" #{added_item.totoal_price}"  />
                    </h:column> 

                    <h:column >
                        <f:facet name="header"> حالة المنتج </f:facet>

                        <h:outputText value="بدون قيمة" rendered="#{added_item.billItemStatus=='WithoutValue' and not added_item.editable}" />
                        <h:outputText value="إرتجاع" rendered="#{added_item.billItemStatus=='SalesReturn' and not added_item.editable}" />
                        <h:outputText value="إعدام" rendered="#{added_item.billItemStatus=='ProductExecution' and not added_item.editable}" />
                        <h:outputText value="عادى" rendered="#{added_item.billItemStatus=='Regular' and not added_item.editable}" />
                        <h:outputText value="عادى" rendered="#{added_item.billItemStatus==null and not added_item.editable}" />

                        <p:selectOneRadio  id="itemStatus" value="#{added_item.billItemStatus}" rendered="#{added_item.editable}">  
                            <f:selectItem itemValue="Regular" itemLabel="عادى"/>
                            <f:selectItem itemValue="ProductExecution" itemLabel="إعدام"/>
                            <f:selectItem itemValue="SalesReturn" itemLabel="إرتجاع"/>
                            <f:selectItem itemValue="WithoutValue" itemLabel="بدون قيمة"/>  
                        </p:selectOneRadio>  
                    </h:column>

                    <h:column>
                        <f:facet name="header">Action</f:facet>
                        <h:commandButton value="تعديل" action="#{billInformationController.editAction(added_item)}" rendered="#{not added_item.editable}" class="btn btn-primary" />
                        <h:commandButton value="حفظ" action="#{billInformationController.saveAction(added_item)}" rendered="#{added_item.editable}" class="btn btn-primary" />
                        <h:commandButton value="مسح" action="#{billInformationController.deleteAction(added_item)}" class="btn btn-primary" />
                    </h:column>
                </h:dataTable>

                <div class="clear"></div>
                <div class="form-inline well">
                    <label style="padding-right:10px; padding-left: 10px;" for="tot">الاجمالى   </label> 
                    <h:inputText size="10" value="#{billInformationController.billTotal}" id="tot" readonly="true"/>
                    <label style="padding-right:10px; padding-left: 10px;" for="pay">المبلغ المدفوع</label>
                    <h:inputText size="10" value="#{billInformationController.paied}" id="pay">
                        <f:ajax execute="@form" render="rem" event="blur" listener="#{billInformationController.itemListener}"/>
                    </h:inputText>
                    <label style="padding-right:10px; padding-left: 10px;" for="rem">الباقى    </label> 
                    <h:inputText size="10" value="#{billInformationController.bill_reminder}" id="rem" readonly="true"/>
                    <div class="clear"></div>
                    <label style="padding-right:10px; padding-left: 10px;" for="disc">الخصم  </label>
                    <h:inputText size="10" value="#{billInformationController.discount}" id="disc">
                    </h:inputText>
                    <h:selectBooleanCheckbox value="#{billInformationController.noExistence}" id="non"></h:selectBooleanCheckbox>
                    <label style="padding-right:10px; padding-left: 10px;" for="non">تالف</label> 
                    <div class="clear"></div>
                    <center>
                        <h:commandButton value="تم " action="#{billInformationController.confirmValues()}" class="btn btn-primary"/>
                    </center>
                </div>
            </h:form>
        </ui:define>
    </ui:composition>
</html>
